#include <stdio.h>

#include <unistd.h>

#include <sys/time.h>

#include <thrift/protocol/TBinaryProtocol.h>

#include <thrift/protocol/TMultiplexedProtocol.h>

#include <thrift/processor/TMultiplexedProcessor.h>

#include <thrift/transport/TSocket.h>

#include <thrift/transport/TTransportUtils.h>

#include "UserStorage.h"
#include "UserSearch.h"

using namespace std;

using namespace apache::thrift;

using namespace apache::thrift::protocol;

using namespace apache::thrift::transport;

using namespace  ::thrift::multiples::demo;

using namespace boost;

int main() {

/*
  shared_ptr<TTransport> socket(new TSocket("localhost", 9090));

  shared_ptr<TTransport> transport(new TBufferedTransport(socket));

  shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));

  UserStorageClient client(protocol);


*/


    shared_ptr<TSocket> transport(new TSocket("127.0.0.1", 9090));
    transport->open();

    shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport));
    shared_ptr<TMultiplexedProtocol> mp1(new TMultiplexedProtocol(protocol, "UserStorage"));
    shared_ptr<UserStorageClient> service1(new UserStorageClient(mp1));
    shared_ptr<TMultiplexedProtocol> mp2(new TMultiplexedProtocol(protocol, "UserSearch"));
    shared_ptr<UserSearchClient> service2(new UserSearchClient(mp2));



    try {

        transport->open();

        UserProfile user;
		
		UserProfile user2;

        user.id = 1;
		user2.id = 2;

        user.name = "liqb";
		user2.name = "liqb2";
		
        user.blurb = "aaaaaa";
		user2.blurb = "bbbbb";

        client.store(user);
		client.store(user2);

        UserProfile1 user3;

        client.getUser(user3, 2);

        printf("user.id = %d user.name = %s user.blurb = %s\n", user3.id, user3.name.c_str(), user3.blurb.c_str());

        transport->close();

    }
    catch (TException &tx)
    {

        printf("ERROR: %s\n", tx.what());

    }





    return 0;
}
